<?php

/**
 * This is the model class for table "medco.staffs".
 *
 * The followings are the available columns in table 'medco.staffs':
 * @property integer $staffId
 * @property integer $staffCategoryCode
 * @property integer $gender
 * @property integer $jobTitleId
 * @property string $firstName
 * @property string $lastName
 * @property string $middleInitial
 * @property string $dateOfBirth
 * @property string $comments
 * @property string $createdBy
 * @property string $createdTime
 * @property string $updatedBy
 * @property string $updatedTime
 * @property integer $hospitalId
 *
 * The followings are the available model relations:
 * @property Staffaddress[] $staffaddresses
 * @property Staffcategory $staffCategoryCode0
 * @property Jobtitle $jobTitle
 * @property Hospital $hospital
 * @property Users[] $users
 */
class Staffs extends MedcoCActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Staffs the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'medco.staffs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('staffCategoryCode, gender, jobTitleId, firstName, lastName, dateOfBirth, hospitalId', 'required'),
			array('staffCategoryCode, gender, jobTitleId, hospitalId', 'numerical', 'integerOnly'=>true),
			array('firstName', 'length', 'max'=>75),
			array('lastName', 'length', 'max'=>100),
			array('middleInitial, createdBy, updatedBy', 'length', 'max'=>10),
			array('comments', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('staffId, staffCategoryCode, gender, jobTitleId, firstName, lastName, middleInitial, dateOfBirth, comments, createdBy, createdTime, updatedBy, updatedTime, hospitalId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'staffaddresses' => array(self::HAS_MANY, 'Staffaddress', 'staffId'),
			'staffCategoryCode0' => array(self::BELONGS_TO, 'Staffcategory', 'staffCategoryCode'),
			'jobTitle' => array(self::BELONGS_TO, 'Jobtitle', 'jobTitleId'),
			'hospital' => array(self::BELONGS_TO, 'Hospital', 'hospitalId'),
			'users' => array(self::HAS_MANY, 'Users', 'staffId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'staffId' => 'Staff',
			'staffCategoryCode' => 'Staff Category Code',
			'gender' => 'Gender',
			'jobTitleId' => 'Job Title',
			'firstName' => 'First Name',
			'lastName' => 'Last Name',
			'middleInitial' => 'Middle Initial',
			'dateOfBirth' => 'Date Of Birth',
			'comments' => 'Comments',
			'createdBy' => 'Created By',
			'createdTime' => 'Created Time',
			'updatedBy' => 'Updated By',
			'updatedTime' => 'Updated Time',
			'hospitalId' => 'Hospital',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('staffId',$this->staffId);
		$criteria->compare('staffCategoryCode',$this->staffCategoryCode);
		$criteria->compare('gender',$this->gender);
		$criteria->compare('jobTitleId',$this->jobTitleId);
		$criteria->compare('firstName',$this->firstName,true);
		$criteria->compare('lastName',$this->lastName,true);
		$criteria->compare('middleInitial',$this->middleInitial,true);
		$criteria->compare('dateOfBirth',$this->dateOfBirth,true);
		$criteria->compare('comments',$this->comments,true);
		$criteria->compare('createdBy',$this->createdBy,true);
		$criteria->compare('createdTime',$this->createdTime,true);
		$criteria->compare('updatedBy',$this->updatedBy,true);
		$criteria->compare('updatedTime',$this->updatedTime,true);
		$criteria->compare('hospitalId',$this->hospitalId);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}